package com.luban.cloud.config;

import com.luban.cloud.EventInstanceRegister;
import com.luban.cloud.InstanceConfigImpl;
import com.luban.moudle.controller.ApplicationController;
import com.luban.moudle.instance.InstanceConfig;
import com.luban.moudle.register.Register;
import com.luban.moudle.servlet.LuBanDispatcherServlet;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

import javax.servlet.Servlet;
import java.util.Arrays;

@EnableConfigurationProperties(RegisterConfigProperties.class)
public class AppConfig {

    @Bean
    public ApplicationController applicationController(Register register,InstanceConfig instanceConfig){
        return  new ApplicationController(register,instanceConfig);
    }

    @Bean
    public Register register(){
        return  new EventInstanceRegister();
    }

    @Bean
    public InstanceConfig instanceConfig(){
        return  new InstanceConfigImpl();
    }

    @Bean
    public ServletRegistrationBean servletRegistrationBean(){
        ServletRegistrationBean<Servlet> servletServletRegistrationBean = new ServletRegistrationBean<>();
        LuBanDispatcherServlet luBanDispatcherServlet = new LuBanDispatcherServlet();
        servletServletRegistrationBean.setServlet(luBanDispatcherServlet);
        servletServletRegistrationBean.setLoadOnStartup(1);
        servletServletRegistrationBean.setUrlMappings(Arrays.asList("*.do"));
//      servletServletRegistrationBean.setUrlMappings();
        return servletServletRegistrationBean;
    }



}
